/**
 * Created by ZYMS on 2018/5/7.
 */

$(function(){
   
    if (newsType == "") {
        window.location.href='http://redscarf.saile.cc/';
    }
    
    getData(1);
    
})

function getData(page){
    var url = "/pioneer/news/getNewsList.html";
    var newsType=$("#newsType").val();
    var postData = {newsType:newsType, page:page,  pageSize:10};
    
    $.ajax({
        type: 'POST',
        url: url,
        async: true,
        data:postData,
        dataType:'json',
        success:function(data) {
            console.log(data);
            if(newsType = ""){
                layer.msg('操作失败!',{icon : 5,time : 1000});
                console.log(data.msg);
                return;
            }
            
            showData(data.data);

            if (page > 1) {
                return;
            }
            laypage({
                cont: 'demo1',
                skin: '#f59d00',
                pages: data.data.pages,
                jump: function (obj, first) {
                    if (!first) { //点击跳页触发函数自身，并传递当前页：obj.curr
                        getData(obj.curr);
                    }

                }
            });
        }
        
    })
}

function  change(){
    getData();
}

function showData(data) {

    var html = "";
    
    for(i=0;i<data.list.length;i++){
        html+="<li>";
        html+="<a href=\"/pioneer/news/news.html?tid="+data.list[i].tid+"\">";
        html+="<div class=\"img_box\">";
        html+="<img src=\""+picPath+data.list[i].newsTitlePic+"\" alt=\"\">";
        html+=" </div>";
        html+="<div class=\"positive\">";
        html+="<h3>"+data.list[i].title+"</h3>";
        html+="<span class=\"details\"> "+data.list[i].newsIntro+"</span>";
        html+="<div class=\"timer\">"+(new Date(data.list[i].createTime).Format("yyyy-M-d h:m")  )+"<span>来源:&nbsp;&nbsp;"+data.list[i].source+"</span></div>";
        html+="</div>";
        html+="</a>";
        html+="</li>";
    }
    $(".box_le ul").html(html);
}